package com.training.servlets;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class PreferenceServlet
 */
public class PreferenceServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public PreferenceServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String dbURL = (String) request.getServletContext().getInitParameter(
				"DB_URL_2");
		
		System.out.println("In Preference from Login"+  request.getServletContext().getAttribute("FROM_LOGIN"));

		System.out.println("DB URL is - " + dbURL);

		String firstName = request.getParameter("firstName");
		String lastName = request.getParameter("lastName");
		String[] sports = request.getParameterValues("sports");
		String food = request.getParameter("food");
		String language = request.getParameter("language");

		System.out.println(" User Preferences are -----");

		System.out.println(" First Name -  " + firstName);
		System.out.println(" Last Name -  " + lastName);
		System.out.println(" Sprots Selected -  ");

		for (int i = 0; i < sports.length; i++) {

			System.out.print(sports[i] + "   ");

		}

		System.out.println("\n Food Selected -  " + food);
		System.out.println(" Language Selected -  " + language);

	}
}
